package com.hmdp.ThreadUtil.pc;/**
 * @Author:fengxiaohui
 * @Description:
 * @Date:Create in 4:13 下午 2023/6/7
 * @Modified By:
 */

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 *@Author:fengxiaohui
 *@Description:
 *@Date:Create in 4:13 下午 2023/6/7
 *@Modified By:
 */
public class SyncDemo {
    public static void main(String[] args) {
        Phone phone1 = new Phone();
        Phone phone2 = new Phone();
        new Thread(()->{
            phone1.sendSms();
            try {
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        },"a").start();
        new Thread(()->{
            phone1.call();
        },"b").start();
        new Thread(()->{
            phone1.sendEmail();
        },"b").start();

    }

}
@Slf4j(topic="Thread")
class Phone{

    public static synchronized void sendSms(){
        log.debug( "{} haha,我在发短信",Thread.currentThread().getName());
    }

    public static synchronized void call(){
        log.debug("{} haha,我在打电话",Thread.currentThread().getName());
    }

    public synchronized void sendEmail(){
        log.debug("{} haha,我在发邮件",Thread.currentThread().getName());
    }
}
